package org.example.blog_system.controller;

import org.example.blog_system.model.UserInfo;
import org.example.blog_system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/check")
   public Integer check(String username , String password ,String inputCaptcha , HttpSession session){
       Integer check =   userService.checkUser(username, password , inputCaptcha, session);
      return check ;
    }

    @RequestMapping("/curUser")
    public UserInfo curUser(HttpSession session , Integer blogId){
        if(session == null || session.getAttribute("userInfo") == null){
            return null;
        }
            UserInfo userInfo = userService.getUserInfo(session , blogId);
        return userInfo ;
    }
    @RequestMapping("/outUser")
    public boolean outUser(HttpSession session){
       return userService.outUser(session);
    }

     // 判断博客 是否是 目前用户的
    @RequestMapping("/isUser")
    public boolean isUser(HttpSession session , Integer blogId){

          return userService.isUser(session , blogId);

    }
    @RequestMapping("/createUser")
    public boolean createUser(HttpSession session ,UserInfo userInfo ,
                              String againPassword){
       boolean flg =  userService.createUser(session,userInfo , againPassword);

        return flg  ;
    }

}
